package org.noranj.me.server.ws;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.noranj.me.server.data.DAService;
import org.noranj.me.server.dto.ConversationDTO;


@Path("/conversation/")
public class ConversationImpl {

  
  public ConversationImpl() {
    super();
  }
  
  @GET
  @Path("/about")
  @Produces("application/json")
  public String about() {
    return("Jingle Board version 1.0");
  } 
  
   
  @GET
  @Path("/conversations/")
  @Produces(MediaType.APPLICATION_JSON)
   public List<ConversationDTO> getConversation(){
    List<ConversationDTO> mylist = new ArrayList<ConversationDTO>();
    for (ConversationDTO row : DAService.getInstance().getConversation().values()){
      mylist.add(row);
    }
    return mylist;
 }
  
  @POST
  @Path("/addrow/")
  public Response addConversation(ConversationDTO converationRow){
    DAService.getInstance().getConversation().put(String.valueOf(converationRow.getIdConversation()) ,converationRow);
    return Response.ok(converationRow).build();
    
  }
  
  @DELETE
  @Path("/deleteall/")
  public Response deleteConversation(){
    DAService.getInstance().getConversation().remove(null);
    return Response.ok().build();
  }
  
  
}
